#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include "ui_mainwindow.h"

class CellWidget;
class QSound;
class QLCDNumber;

class MainWindow: public QMainWindow {
Q_OBJECT

public:
	MainWindow(QWidget *parent = 0);
	~MainWindow();

protected:
	virtual void closeEvent(QCloseEvent *);

private:
	enum Skill {
		Novice, Normal, Expert, Master
	};
	enum BoardSize {
		NoviceBoardSize = 5,
		NormalBoardSize = 7,
		ExpertBoardSize = 9,
		MasterBoardSize = 9
	};
	enum {
		NumHighscores = 10, MinimumNumCells = 20
	};

	typedef QList<CellWidget *> CellList;

	void setSkill(int s);

	void addRandomDir(CellList & list);

	CellWidget * uCell(CellWidget * cell, bool wrap) const;
	CellWidget * dCell(CellWidget * cell, bool wrap) const;
	CellWidget * lCell(CellWidget * cell, bool wrap) const;
	CellWidget * rCell(CellWidget * cell, bool wrap) const;

	bool isGameOver();
	bool updateConnections();
	void addHighscore(int score);

private slots:
	void newGame();
	void triggeredSkill(QAction *);
	void noRotation();
	void startRotation();
	void finishRotation();
	void showHighscores();

private:
	Ui::MainWindowClass ui;

	int skill;
	bool wrapped;

	CellWidget * root;
	CellWidget * board[MasterBoardSize * MasterBoardSize];

	QSound * clickSound;
	QSound * connectSound;
	QSound * startSound;
	QSound * turnSound;
	QSound * winSound;

	QString user;
	QAction * soundAction;
	QStringList highscores;

	QLCDNumber * lcd;
};

#endif // MAINWINDOW_H
